import {
  MessageNotice,
  UpdateMessage
} from '../../../config/api'
import util from '../../../utils/util'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [], //个人中心未读消息列表
    res: {}, //删除结果数据
    page: 1,
    isEmpty: false, //判断是否有数据
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let member = wx.getStorageSync("member");
    let grider_storge = wx.getStorageSync('grider')
    let type = options.type;

    if (type == 1) {
      var params = {
        uid: member.id,
        type: 1
      }
    } else if (type == 2) {
      var params = {
        uid: grider_storge.id,
        type: 2
      }
    }

    let that = this;
    util.apiRequest(UpdateMessage, params, null).then(r => {
      console.log('消息更新：', r)
    })

    util.apiRequest(MessageNotice, params, null).then(r => {
      console.log('消息列表：', r.data.data.data);
      if (r.data.data.data.length == 0) {
        that.setData({
          isEmpty: true
        });
      } else {
        that.setData({
          list: r.data.data.data,
        });
      }
    });
  },

  /**
   * 点击删除消息
   */
  delMessage: function (e) {
    let that = this;
    wx.showModal({
      title: '提示',
      content: '是否确认删除',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')

          // this.onload();
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

})